package com.whut.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.whut.entity.Courier;
import com.whut.entity.User;
import com.whut.service.CourierService;
import com.whut.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

@Slf4j
@RestController
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    private CourierService courierService;
    @Autowired
    private UserService userService;
    /**
     * 统计快递员总数
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/sumCourier.do")
    public String getSumCourier(HttpServletRequest request , HttpServletResponse response){
        int count = courierService.count();
        return count+"";
    }

    /**
     * 获取快递员日增量
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/todayCourier.do")
    public String getTodayCourier(HttpServletRequest request , HttpServletResponse response){
        LambdaQueryWrapper<Courier> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(Courier::getCreateTime, LocalDate.now());
        int count = courierService.count(queryWrapper);
//        int count = courierDao.countToday();
        return count+"";
    }

    /**
     * 获取用户总数
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/sumUser.do")
    public String getSumUser(HttpServletRequest request , HttpServletResponse response){
        int count = userService.count();
        return count+"";
    }

    /**
     * 获取用户日增量
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/todayUser.do")
    public String getTodayUser(HttpServletRequest request , HttpServletResponse response){
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(User::getCreateTime, LocalDate.now());
        int count = userService.count(queryWrapper);
        return count+"";
    }

}
